package com.gzy.rpsm_property.mapper;

import com.gzy.rpsm_property.pojo.Message;
import com.gzy.rpsm_property.pojo.Messages;
import com.gzy.rpsm_property.pojo.Ms;
import com.gzy.rpsm_property.pojo.Reply;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface MessageMapper {
    @Select("SELECT message_id,message_userid,message_content,message_publish_time,message_title FROM message WHERE message_id = #{messageId}")
    Message getMessageById(@Param("messageId") int message);

    @Select("SELECT * FROM message")
    List<Ms> findAllMessages();

    @Select("SELECT u.userid, u.account, u.password, u.idcard, u.username, u.gender, u.age, u.user_type, u.user_status, u.user_roomid, u.user_avatar, " +
            "m.message_id, m.message_userid, m.message_content, m.message_publish_time, m.message_title " +
            "FROM user u " +
            "LEFT JOIN message m ON u.userid = m.message_userid " +
            "WHERE u.username = #{username}")
    List<Ms> findUserAndMessagesByUsername(@Param("username") String username);


    void insertMessage(Messages messages);
    @Update("UPDATE message SET message_content = #{messageContent}, message_title = #{messageTitle} WHERE message_id = #{messageId}")
    void updateMessage(Message message);


    @Insert("INSERT INTO reply (reply_messageId, reply_user_name, reply_message_title, reply_message_content, reply_time) " +
            "VALUES (#{replyMessageId}, #{replyUserName}, #{replyMessageTitle}, #{replyMessageContent}, #{replyTime})")
    void insertReply(Reply reply);
}




